package nl.fonfolio.view.createavatar {
	import flash.display.Sprite;
	import flash.display.MovieClip;
	import flash.text.TextField;	

	/**
	 * @author lindy
	 */
	public class AvatarElement extends Sprite {
		private var sort : String;
		private var spacing : Number = 9;
		private var container : Sprite = new Sprite();
		public var element_lbl : TextField;
		public var skincolor_lbl : TextField;

		public function AvatarElement(sort : String, scale : Number) {
			this.sort = sort;
			this.container.x = 20;
			this.container.y = 45;
			
			this.element_lbl.text = "Selecteer "+sort
			
			addChild(container);
			elementList(scale);
		}

		private function elementList(scale : Number = 2) : void {
			var element : MovieClip = createElement(sort);
			var thumb : MovieClip;
			for (var i : Number = 0;i < element.totalFrames; i++) {
				thumb = new ElementThumb();
				thumb.x = (i % 5) * (thumb.width + spacing);
				thumb.y = Math.floor(i / 5) * (thumb.width + spacing);

				element = createElement(sort);
				element.scaleX = element.scaleY = scale;
				element.x = thumb.width / 2;
				element.y = thumb.height / 2;
				element.gotoAndStop(i + 1);
				thumb.addChild(element);
				container.addChild(thumb);
			}
		}

		private function createElement(sort : String) : MovieClip {
			switch (sort) {
				case "eye" :
					return new Eye()  ;
					break;
				case "nose" :
					return new Nose()  ;
					break;
				case "mouth" :
					return new Mouth()  ;
					break;
				case "face" :
					return new Face()  ;
					break;
				default :
					return new MovieClip  ;
					break;
			}
		}
	}
}
